<?php 
ini_set('display_errors', 1); 
ini_set('error_reporting', 'E_error'); 
 require_once "../includes/config.php";
 ?>
<script type="text/javascript">
function update_service(fid)
{
       window.location="index.php?edit_feedback&fid="+fid;
}
function memfeedback(fid) {
	window.location='index.php?viewfeedback&fid='+fid;
}
function funDelMem(fid) {
var delPro=confirm("Are you sure want to delete feedback?");
if(delPro==true) {
       var frm = document.getElementById('form1');
       document.getElementById("hidefid").value=fid;
       frm.submit();
}	
}
</script>
 <?
if(!empty($_POST['hidefid']))
{
       $fid=$_POST['hidefid'];
       $sqlDelMem="Delete from tbl_feedback where fid=$fid";
       $rstDelMem=mysql_query($sqlDelMem);	
}

$cond = '';
$sort = '';
$ut = $u = $fn = $ln = $dg = 'asc';
if(isset($_GET['sort']))
{
 if($_GET['sort']=='post_on')
 {
  if($_GET['s_type']=='asc')
  {	$cond=' ORDER BY post_on ASC';	$sort = '&sort=product_name&s_type=asc';	$ut='desc';	}
  else
  {	$cond=' ORDER BY post_on DESC';	$sort = '&sort=product_name&s_type=desc';	}
 }
 
}
 
?>
<form action="" method="post" name="form1" id="form1" name="formService" id="formService">
       <input type="hidden" name="hidefid" id="hidefid">
<table width="100%"  border="1" cellspacing="0" class="container">
       <tr>
	 <td width="469" height="25" class="tdHeader">Feedback <span style="text-align:right; padding-left:350px;"></span></td>
       </tr>  
       <tr>
	      <td height="577">	
		     <table width="100%">
			    <tbody>
				   <tr>
					  <td>
						 <form name="frmSearchPro" action="" method="post">
							<table width="100%" border="0">
							       <tr>
								      <td width="20%">Posted on</td>
								      <td width="30%">
									      <input type="text" name="post_on" id="post_on" style="width: 150px;" value="<?php echo $_POST['post_on']?>" />
								      </td>
								      <td width="20%">Posted by</td>
								      <td width="30%"><input type="text" name="post_by" id="post_by" style="width: 150px;" value="<?php echo $_POST['post_by']?>" /></td>
							       </tr>
							      
				  
							       <tr>
								       <td height="35" colspan="5" style="text-align:center"><input type="submit" name="btnSearchPro" value="Search" /></td>
							       </tr>
							</table>
						 </form>
					  </td>
				   </tr>
				   <tr>
					  <td>
						 <b>Sort  By :</b>
						 <a href="<?php echo $base_url;?>admin/index.php?feedback&sort=post_on&s_type=<?php echo $ut;?>">Post date</a> &nbsp;&nbsp;&nbsp;
					  </td>
				   </tr>
			    </tbody>
		     </table><br>
		     <table width="100%"  border="0" cellspacing="0">
			    
			    <tr class="InnerHeader">
			      <td width="1%"  class="line">&nbsp;</td>
			      <td width="18%" class="line">Feedback</td>
			      <td width="14%" class="line">Trans. no</td>
			      <td width="12%" class="line">Posted to</td>
			      <td width="15%" class="line">Posted by</td>
			      <td width="7%" class="line">Rate</td>
			      <td width="16%" class="line">Post Date</td>
			      <td width="3%" class="line"></td>
			      <td width="3%" class="line"></td>
			       <td width="11%" class="line"></td>
			    </tr>	 
			    <?php
			    //$itemPerPage=15;
			    $search='';
			    if(isset($_POST['btnSearchPro'])) {
				    
				    $post_on 	= $_POST['post_on'];		
				    $post_by 		= $_POST['post_by'];
				   
				    
				   if($post_on!='')
				   $search.= "where comm_to IN (select user_id from tbl_users where username LIKE '%$post_on%')";
				   
				 				   
				   if($post_on!='') {
					  if($post_by!='')
						 $search.=" AND comm_by IN (select user_id from tbl_users where username LIKE '%$post_by%')";
				   }
				   else {
					  if($post_by!='')
						 $search.="where comm_by IN (select user_id from tbl_users where username LIKE '%$post_by%')";
				   }
				    
				
				    
			    }
			    $sqlShwSubcat="select * from tbl_feedback $search $cond";
			    $rstShwSubcat=mysql_query($sqlShwSubcat);
			    $numShwSubcat=mysql_num_rows($rstShwSubcat);
			    if($numShwSubcat==0) 
			    {
				   echo "<tr><td></td><td colspan='4'><h3>No feedback Found...</h3></td></tr>";
			    }
			    else 
			    {
				   while($rowShwSubCat=mysql_fetch_array($rstShwSubcat)) 
				   {
					  $transno="";
					   $transno1="";
					  $fid=$rowShwSubCat['fid'];
					  $rate=$rowShwSubCat['rate'];
					  $post_date=$rowShwSubCat['post_on'];
					  $comm_to=getUser($rowShwSubCat['comm_to']);
					  $comm_by=getUser($rowShwSubCat['comm_by']);
					  $comment=$rowShwSubCat['comment'];
					  if(strlen($comment)>10)
					   $comment=substr($comment,0,10)."...";
					  $post_on=$rowShwSubCat['post_on'];
					  $rate=$rowShwSubCat['rate'];
					  $order_id=$rowShwSubCat['order_id'];
					  
					  $seltrans=mysql_query("select * from tbl_orders where order_id=$order_id");
					  $roworder=mysql_fetch_array($seltrans);
					  $transno=$roworder['transaction_ID'];
					  if($transno!="")
					  $transno1=substr($roworder['transaction_ID'],0,10);
					  
					  	if($rate==1)
						  $srate="Great";
						else if($rate==2)
						  $srate="Acceptable";
						else if($rate==3)
						  $srate="Negative";
					
					  
					  echo "<tr>";
					  echo "<td class='line'>&nbsp;</td>";
					  echo "<td class='line'>$comment</td>";
					  echo "<td class='line' title='".$transno."'>$transno1</td>";
					  echo "<td class='line'>$comm_to</td>";
					  echo "<td class='line'>$comm_by</td>";
                      echo "<td class='line'>$srate</td>";
                      echo "<td class='line'>$post_date</td>";
					  echo "<td class='line'><input type='button' name='edit' value='Edit' class='button' onclick='update_service($fid);'></td>";
					   echo "<td class='line'><input type='button' name='view' value='View' class='button'  onclick='memfeedback($fid)'></td>";
					  echo "<td height='20' class='line'><input type='button' name='delete' value='Delete' class='button'  onclick='funDelMem($fid)';></td> ";
					  echo "<td height='20' class='line'></td> ";
					  echo "</tr>";
				   }
			    }
			    ?>
			    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td></td><td></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
		     </table>
	      </td>
       </tr>
</table>
</form>